﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;
using System.Web.Security;

namespace Zebra.Umbraco.Marcos.MailList
{
    public partial class NewMailList : LoginRequiredControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            if (db.surveyMailLists.Count(c => c.Name == TextBox1.Text.Trim() && c.NodeID == int.Parse(Membership.GetUser().ProviderUserKey.ToString())) == 0)
            {

                surveyMailList mailList = new surveyMailList()
                {
                    NodeID = int.Parse(Membership.GetUser().ProviderUserKey.ToString()),
                    Name = TextBox1.Text.Trim(),
                    RowCreatedOn = DateTime.Now,
                    RowModifiedOn = DateTime.Now
                };
                db.surveyMailLists.InsertOnSubmit(mailList);
                db.SubmitChanges();
                Response.Redirect(string.Format("/MailList/{0}/Detail.aspx", mailList.MailListID));
            }
            else
            {
                Label1.Visible = true;
            }

            
        }
    }
}